﻿namespace LogManager.Gui.UI.Representations
{
    using LogManager.Core.Infrastructure.Logging;
    using LogManager.Gui.UI.Helpers;
    using System;
    using System.Windows.Media;

    public class LogItem
    {
        public string Message { get; private set; }
        public string Details { get; private set; }
        public ImageSource Icon { get; private set; }
        public string Time { get; private set; }

        public LogItem(LogResult logResult)
        {
            this.Message = logResult.Message;
            this.Details = logResult.Details;
            this.Icon = GetIconForType(logResult.LogType);
            this.Time = DateTime.Now.ToLongTimeString();
        }

        private ImageSource GetIconForType(LogType logType)
        {
            switch (logType)
            {
                case LogType.Info:
                    return ImageHelpers.loadResource<ImageSource>("images/info.png");
                case LogType.Success:
                    return ImageHelpers.loadResource<ImageSource>("images/accept.png");
                case LogType.Warning:
                    return ImageHelpers.loadResource<ImageSource>("images/warning.png");
                case LogType.Error:
                    return ImageHelpers.loadResource<ImageSource>("images/error.png");
                default:
                    throw new Exception("Unknown LogType " + logType);
            }
        }
    }
}
